﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using Model;
using FubiManger.UI;
namespace FubiManger.Controls
{
    ////ToolboxItem用于控制是否添加自定义控件到工具箱，true添加，false不添加
    //[System.ComponentModel.ToolboxItem(true)]
    partial class goodscontrol : Smobiler.Core.Controls.MobileUserControl
    {
        public goodscontrol() : base()
        {
            //This call is required by the SmobilerUserControl.
            InitializeComponent();
        }
        /// <summary>
        /// 商品名称
        /// </summary>
        public string goodname { get; set; }
        /// <summary>
        /// 分类ID
        /// </summary>
        public string classify_id { get; set; }
        /// <summary>
        /// 封面
        /// </summary>
        public string cover { get; set; }
        /// <summary>
        /// 销售价
        /// </summary>
        public string price { get; set; }
        /// <summary>
        /// 市场价
        /// </summary>
        public string market_price { get; set; }
        /// <summary>
        /// 1上架2下架
        /// </summary>
        public string status { get; set; }
        /// <summary>
        /// 商品ID
        /// </summary>
        public string goodid { get; set; }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        private void goodscontrol_Load(object sender, EventArgs e)
        {

            if (lblstatus.Text == "1")
                swstatus.Checked = true;
            //lblname.Text = goodname;//商品名称
            //imgcover.ResourceID = @"C:\fbimage\" + cover;
            //lblprice.Text = "￥" + price;//价格
            //lblmarkprice.Text = "原价￥" + market_price;//市场价
            //lblclassname.Text = classifyDal.Querybyid(classify_id);
        }

        private void swstatus_CheckedChanged(object sender, EventArgs e)
        {
            if (swstatus.Checked == true)
            {
                if (goodsDal.Updatestatus("1", lblgoodid.Text) > 0)
                {
                    Toast("商品上架成功");
                    ((GoodsForm)this.Form).Resfh();//刷新

                }
            }
            else
            {
                if (goodsDal.Updatestatus("2", lblgoodid.Text) > 0)
                {
                    Toast("商品下架成功");
                    ((GoodsForm)this.Form).Resfh();//刷新
                }
            }

        }
        /// <summary>
        /// 菜单分类
        /// </summary>
        private void Getpop()
        {
            if (popgoodlist.Groups.Count > 0)
                popgoodlist.Groups.Clear();
            PopListGroup gp = new PopListGroup();
            List<ms_classify> cllist = classifyDal.Querybymerid(lblmerchantid.Text);
            for (int i = 0; i < cllist.Count; i++)
            {
                PopListItem item = new PopListItem();
                item.Text = cllist[i].title;
                item.Value = cllist[i].id;
                gp.Items.Add(item);
            }
            popgoodlist.Groups.Add(gp);
        }
        /// <summary>
        /// 选择商品分类
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnclassname_Press(object sender, EventArgs e)
        {
            Getpop();//加载商品分类
            popgoodlist.ShowDialog();
        }

        private void popgoodlist_Selected(object sender, EventArgs e)
        {
            lblclassname.Text = popgoodlist.Selection.Text;
            goodsDal.Updateclass(popgoodlist.Selection.Value, goodid);
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void panel1_Press(object sender, EventArgs e)
        {
            AddgoodForm frm = new AddgoodForm();
            frm.merchantid = lblmerchantid.Text;//商户ID
            frm.goodsid = lblgoodid.Text;//商品ID
            frm.stype = "2";
            this.Form.Show(frm, true, (obj, args) =>
            {
                ((GoodsForm)this.Form).Resfh();//刷新
            });
        }
        /// <summary>
        /// 删除商品
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void panel1_LongPress(object sender, EventArgs e)
        {
            MessageBox.Show("点击确定将删除商品", "删除商品", MessageBoxButtons.OKCancel, (obj, args) =>
            {
                if (args.Result == ShowResult.OK)
                {
                    //删除商品
                    if (goodsDal.Delgoods(lblgoodid.Text) > 0)
                    {
                        Toast("删除成功");
                        ((GoodsForm)this.Form).Resfh();//刷新
                    }
                }
            });
        }

        private void btndel_Press(object sender, EventArgs e)
        {

        }
    }
}